package com.google.code.head2head.gwtmodules.client;

import com.google.code.head2head.gwtmodules.client.fileupload.FileUploadPanel;
import com.google.code.head2head.gwtmodules.client.imagepanels.AllEntriesPanel;
import com.google.code.head2head.gwtmodules.client.login.H2HLoginPanel;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SourcesTabEvents;
import com.google.gwt.user.client.ui.TabListener;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class Head2Head implements EntryPoint {
	
	private VerticalPanel bp;

	private H2HLoginPanel lp;

	private VerticalPanel hp2 = new VerticalPanel();

	private VerticalPanel hp = new VerticalPanel();
	
	private TabPanel tabp;
	
	private AllEntriesPanel tp;

	public void onModuleLoad() {



		// a panel to display the images
		initAllImagesPanel();

		// a login panel
		initLoginPanel();
		
		//a file upload panel
		initFileUploadPanel();

		// the tab panel that will display the other panels
		initTabPanel();
		
		// the base panel containing all widgets
		initBasePanel();

		RootPanel.get().add(bp);
	}




	private void initLoginPanel() {
		lp = new H2HLoginPanel();
	}

	private void initAllImagesPanel() {
		hp2.clear();
		hp2.add(new HTML("Click on top of images to open/close"));
		tp = new AllEntriesPanel();
		hp2.add(tp);
	}
	


	private void initFileUploadPanel() {
		// a panel for the file uploads
		hp.clear();
		hp.add(new HTML("Choose files to upload on your computer"));
		FileUploadPanel uploadPanel = new FileUploadPanel();
		hp.add(uploadPanel);
	}
	
	private void initTabPanel(){
		tabp = new TabPanel();
		tabp.add(hp2, "View images");
		tabp.add(lp, "Login");
		tabp.add(hp, "Create new entry");
		tabp.addTabListener(new TabListener(){

			public boolean onBeforeTabSelected(SourcesTabEvents arg0, int arg1) {
				if(arg1==0){
					initAllImagesPanel();
				}
				return true;
			}

			public void onTabSelected(SourcesTabEvents arg0, int arg1) {
				// TODO Auto-generated method stub
				
			}
			
		});
		
		tabp.selectTab(0);
	}
	
	private void initBasePanel(){
		bp = new VerticalPanel();
		bp.add(new HTML("<br><br>"));
		bp.add(tabp);
	}
}